package gui.initiatives;

import gui.DateTimePanel;
import gui.EarthPanel;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import common.Buffer;
import common.StepData;

public class ClockBufferListener implements ActionListener {
  private DateTimePanel pnlDateTime;
  private EarthPanel pnlEarth;
  private Buffer buffer;
  
  public ClockBufferListener(DateTimePanel pnlDateTime, EarthPanel pnlEarth, Buffer buffer) {
    this.pnlDateTime = pnlDateTime;
    this.pnlEarth = pnlEarth;
    this.buffer = buffer;  
  }
  
  public void actionPerformed(ActionEvent e) {
    StepData data = buffer.pop();    
    pnlEarth.updateGrid(data.getGrid());
    pnlEarth.moveSunPosition(data.getDegrees());
    pnlDateTime.increment(data.getMilliSecs());
  }

}
